var CommontUnit = {

    initSelectMethod: function (id, selectData) {
        var sel_Document = $("#" + id);
        for (var n in selectData) {
            //第一个代表标签内的内容，第二个代表value
            var flag = selectData[n].select == true ? 'selected' : 'false';
            sel_Document.append("<option value='" + selectData[n].value + "'" + flag + ">" + selectData[n].value + "</option>");
        }
    },
    callBackMethod: function (url, method, param) {
        $.ajax(
            {
                url: url,
                type: method,
                data: JSON.stringify(param),
                dataType: 'json',
                contentType: 'application/json',

                success: function (data) {
                    console.log("请求成功")
                    console.log(JSON.stringify(data));
                },
                error: function (data) {
                    console.log("请求失败")
                    console.log(JSON.stringify(data));
                }
            });
    },
    initFormDataToJson: function (id) {
        var dataArray = $("#" + id).serializeArray();
        var jsonData = {};
        var n = 0;
        for (var i = 0; i < dataArray.length; i++) {
            if (typeof (jsonData[dataArray[i].name]) != "undefined") {
                if (n == 0) {
                    jsonData[dataArray[i].name] = [];
                    jsonData[dataArray[i].name].push(dataArray[i - 1].value);
                    n++;
                }
                jsonData[dataArray[i].name].push(dataArray[i].value)
            } else {
                jsonData[dataArray[i].name] = dataArray[i].value;
            }
        }
        return jsonData;
    },
    getCheckBoxValues: function (name) {
        var values = [];
        var checkArray = $("input[name='" + name + "']");
        $.each(checkArray, function (i, obj) {
            if (obj.checked) {
                values[i] = obj.value;
            }
        })
        return values;
    },
    initCheckBoxSelectAll: function (name) {
        var checkArray = $("input[type='checkbox'][name='" + name + "']");
        $.each(checkArray, function (i, obj) {
            obj.checked = true;
        })
    },
    initRadioSelectByValue: function (values) {
        var radioElement = $("input[type='radio'][value='" + values + "']");
        radioElement.attr("checked", "checked");
    }
}
